<!DOCTYPE html>
<html lang="en">

<head>
  <title>我的订单</title>
  <link rel="stylesheet" href="/css/total/orderList.css">
  <% include ../component/_common_tongji.html %>
  <% include ../component/common_meta.html %>
</head>

<body>
  <div id="app">
    <div v-if="false" style="font-size:0.3rem;" id="show">您的浏览器版本太低请升级浏览器或者使用Chrome浏览器</div>
    <div class="content" v-cloak>
      <div class="person">
        <div class="per_left">
          <img :src="img">
          <p>{{userInfo.realname != '' ? userInfo.realname : ""}}</p>
          <span>{{userInfo.phone}}</span>
        </div>
        <div class="address" @click="handleGetAddress">
          收货地址
        </div>
      </div>
      <div class="per_right">
        <p class="money">助学金
          <span>{{userInfo.total_money}}</span></p>
        <p class="invitation">成功邀请
          <span>{{userInfo.count}}</span> 位好友</p>
      </div>
      <div class="myOrder">
        我的订单
      </div>
      <div class="orderList" v-for="item in userInfo.order_info" @click="handleOrderDetail(item.order_id)">
        <p class="title">{{item.exam_name}}</p>
        <p class="orderinfo"><span>数量{{item.exam_count}}</span>&nbsp;&nbsp;<span>{{item.exam_option.name}}</span>&nbsp;&nbsp;<span>{{item.exam_option.subject}}</span></p>
        <p>￥{{item.order_price}}</p>
        <img src="/img/right.png" alt="">
        <span class="tag" v-if="item.type != 1">{{item.type == 2 ? '团购': (item.type == 3 ? '预购' : '')}}</span>
      </div>
    </div>
  </div>
  <% include ../component/common_js.html %>
  <!-- Initialize Swiper -->
  <script>
    var app = new Vue({
      el: '#app',
      data: {
        my_invitation_code: '',
        img: '/img/9_02.png',
        token: '',
        userInfo: {
          realname: '',
          phone: '',
          total_money: '0',
          count: '0',
          order_info: []
        }
      },
      mounted: function () {
        if (localStorage.getItem('token') && localStorage.getItem('token') != '') {
          this.token = localStorage.getItem('token')
          this.getUserInfo()
        } else {
          location.href = '/tlmall/login?' + window.location.href;
          return;
        }
      },
      methods: {
        getUserInfo () {
          var vm = this;
          api.post('/api/v2/user/getUserInfo',{
            token: this.token
          }).then(res => {
            if (res.data.res_code == 1) {
              var res_data = res.data.data;
              vm.userInfo.realname = res_data.user_info.realname;
              vm.userInfo.phone = res_data.user_info.phone;
              vm.userInfo.total_money = res_data.share_money_info.total_money;
              vm.userInfo.count = res_data.share_money_info.count;
              vm.userInfo.order_info = res_data.order_info;
              vm.my_invitation_code = res_data.user_info.my_invitation_code;
            } else if (res.data.res_code <= -900) {
              localStorage.removeItem('token');
              window.location.href = '/tlmall/login?' + window.location.href;
            }
          }).catch(err => {
            setLog('/api/v2/user/getUserInfo:catch', JSON.stringify(err));
          })
        },
        handleGetAddress () {
          location.href = '/tlmall/address?address_origin=order';
        },
        handleOrderDetail (order_id) {
          location.href = '/tlmall/order_detail?order_id=' + order_id;
        }
      }
    })


  </script>
</body>

</html>